package com.rongke.web;

import com.rongke.commons.JsonResp;
import com.rongke.model.Message;
import com.rongke.service.MessageService;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @MessageController
 * @消息公告Controller
 * @version : Ver 1.0
 */
@RestController
@RequestMapping(value = "/api/notice")
public class MessageController {
    private static final Logger LOGGER = Logger.getLogger(MessageController.class);

    @Autowired
    private MessageService      messageService;

    /**
     * @根据id查找消息公告
     * @param id
     * @return 返回值JsonResp
     */
    @RequestMapping(value = "/selectOne", method = RequestMethod.GET)
    public JsonResp selectMessage(Long id) {
        LOGGER.debug("查找消息公告");
        Message message = messageService.selectById(id);
        return JsonResp.ok(message);
    }

    @RequestMapping(value = "/selectList", method = RequestMethod.GET)
    public JsonResp selectMsgList() {
        LOGGER.debug("selectMsgList");

        try {
            List<Message> result = messageService.selectFrontPageNotice();

            return JsonResp.ok(result);
        } catch (Exception e) {
            LOGGER.error("selectMsgList failed", e);
            return JsonResp.fa(null);
        }
    }
}
